import java.util.Scanner;

//求1！+2！+3！+4！+........+n!的和
public class Question3 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要求阶乘和的数字：");
        int n =sc.nextInt();

        int retSum = retSum(n);
        System.out.println("阶乘和为："+retSum);


    }

    public static int ret(int n){//一个数的阶乘

        int i = 1;
        int ret = 1;

        while(i <= n){

            ret *= i;
            i++;

        }
        return ret;

    }
    public static int retSum(int n){//把每个数的阶乘加起来

        int i = 1;
        int retSum = 0;

        while(i <= n){

            retSum += ret(i);
            i++;//丢掉这一步会死循环

        }
        return retSum;


    }

}
